
import { ElButton } from 'element-plus';
<template>
  <div class="account-list">
    <div class="account-list-header">
      <div class="account-list-title">
        店铺信息
      </div>

      <ElButton type="primary" plain @click="onAddAccount">添加子账号</ElButton>
    </div>

    <div>
      <ElTable :data="modelValue">
        <ElTableColumn type="index" :width="50" align="center" label="#" />
        <ElTableColumn label="数据账号" prop="accountNo" />
        <ElTableColumn label="子账号名称" prop="accountName" />
        <ElTableColumn label="账号密码" prop="accountPassword" />
        <ElTableColumn label="操作" :width="110" fixed="right">
          <template #default="{ row, $index }">
            <ElButton link type="primary" @click="onEdit(row, $index)">编辑</ElButton>
            <ElButton link type="primary" @click="onRemove($index)">删除</ElButton>
          </template>
        </ElTableColumn>
      </ElTable>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ElButton, ElTable, ElTableColumn } from 'element-plus'
import { addAccountDialog } from '../dialog'

interface Props {
  modelValue: any[];
  data: object;
}

const props = withDefaults(defineProps<Props>(), {
  modelValue: () => [],
  data: () => ({})
})

interface Emits {
  'update:model-value': [any[]]
}
const emit = defineEmits<Readonly<Emits>>()

const onAddAccount = async() => {
  const data = await addAccountDialog.open()
  const val = [...props.modelValue]
  val.push(data)
  emit('update:model-value', val)
}

const onEdit = async (row, index) => {
  const data = await addAccountDialog.open({ row: { ...row } })
  const val = [...props.modelValue]
  val.splice(index, 1, data)
  emit('update:model-value', val)
}

const onRemove = async index => {
  const val = [...props.modelValue]
  val.splice(index, 1)
  emit('update:model-value', val)
}
</script>

<style scoped lang="scss">
.account-list {
  box-sizing: border-box;
  margin: 0 -14px;
  width: calc(100% + 28px);
  padding: 0 14px;
  &-header {
    width:100%;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  &-title {
    height: 44px;
    display: flex;
    align-items: center;
    background: #FFFFFF;
    font-family: PingFangSC-Medium;
    font-weight: 500;
    font-size: 13px;
    color: #757575;
    &::before {
      box-sizing: border-box;
      content: '';
      display: inline-block;
      width: 7px;
      height: 10px;
      border: 2.4px solid #3778FB;
      border-radius: 2px;
      margin-right: 5px;
    }
  }
}
</style>
